package com.tanhua.server.controller;

import com.tanhua.domain.vo.UserInfoVo;
import com.tanhua.server.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/users")
public class UserInfoController {

//    注入UserInfoServcie对象
    @Autowired
    private UserInfoService userInfoService;

    /**
     * 读取用户信息
     */
    @GetMapping
    public ResponseEntity readUsersInfo
    (String userID, String huanxinID) {

//        调用UserInfoServcie方法 传入参数
       UserInfoVo info= userInfoService.readUsersInfo(userID,huanxinID);
//        返回前端需要的参数
        return ResponseEntity.ok(info);
    }

    /**
     * 修改用户信息
     */
    @PutMapping
    public ResponseEntity editUsersInfo
    (@RequestBody UserInfoVo userInfoVo) {
//       调用userInfoService方法 传入userInfoVo对象
        userInfoService.editUsersInfo(userInfoVo);
//       返回响应码
        return ResponseEntity.ok(null);
    }

    /**
     * 修改头像
     */
    @PostMapping("/header")
    public ResponseEntity editUserHeader(MultipartFile headPhoto) {
//        调用userInfoServcie方法 传入headPhoto对象和token
        userInfoService.editUserHeader(headPhoto);
//        返回
        return ResponseEntity.ok(null);
    }


}
